package com.qfedu.openplateform.manager.service.impl;

import com.github.pagehelper.PageHelper;
import com.qfedu.openplateform.manager.dao.ApiMappingMapper;
import com.qfedu.openplateform.manager.entity.ApiMapping;
import com.qfedu.openplateform.manager.service.ApiMappingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApiMappingServiceImpl implements ApiMappingService {

    @Autowired
    private ApiMappingMapper apiMappingMapper;
    @Override
    public List<ApiMapping> getAllApiMapping(ApiMapping apiMapping, int page, int limit) {
        PageHelper.startPage(page, limit);
        List<ApiMapping> apiMappingList = apiMappingMapper.getAllApiMapping(apiMapping);
        return apiMappingList;
    }

    @Override
    public List<ApiMapping> getAllApiMapping() {
        return apiMappingMapper.getAllApiMapping(null);
    }

    @Override
    public ApiMapping getApiMappingById(int id) {
        return apiMappingMapper.getApiMappingById(id);
    }

    @Override
    public int addApiMapping(ApiMapping apiMapping) {
        return apiMappingMapper.addApiMapping(apiMapping);
    }

    @Override
    public int updateApiMapping(ApiMapping apiMapping) {
        return apiMappingMapper.updateApiMapping(apiMapping);
    }

    @Override
    public void deleteApiMapping(int[] ids) {
        for (int id : ids) {
            ApiMapping apiMapping = apiMappingMapper.getApiMappingById(id);
            if (apiMapping != null) {
                apiMapping.setState(0);
                apiMappingMapper.updateApiMapping(apiMapping);
            }
        }
    }
}
